package com.lanyan.web.controller.courier;

import com.lanyan.common.annotation.Log;
import com.lanyan.common.annotation.RepeatSubmit;
import com.lanyan.common.core.controller.BaseController;
import com.lanyan.common.core.domain.AjaxResult;
import com.lanyan.common.core.domain.PageR;
import com.lanyan.common.core.domain.R;
import com.lanyan.common.enums.BusinessType;
import com.lanyan.common.utils.SecurityUtils;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.domain.Opinion;
import com.lanyan.system.domain.vo.OpinionVo;
import com.lanyan.system.service.IOpinionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;

/**
 * 投诉建议Controller
 *
 * @author lanyan
 * @date 2024-11-26
 */
@RestController
@Api(tags = {"配送员-投诉建议"})
@RequestMapping("/courier/opinion")
public class CourierOpinionController extends BaseController {
    @Autowired
    private IOpinionService opinionService;

    /**
     * 查询投诉建议列表
     */
    @GetMapping("/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "第几页", dataType = "int", dataTypeClass = int.class),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", dataTypeClass = int.class),

    })
    @ApiOperation("查询投诉建议列表")
    public PageR<Opinion> list(@ApiIgnore Opinion opinion) {
        startPage();
        opinion.setAccountId(SecurityUtils.getUserId());
        List<Opinion> list = opinionService.selectOpinionList(opinion);
        return PageR.page(list);
    }

    /**
     * 获取投诉建议详细信息
     */
    @GetMapping(value = "/info")
    @ApiOperation("获取投诉建议详细信息")
    public R<Opinion> getInfo(Long opinionId) {
        return R.ok(opinionService.selectOpinionByOpinionId(opinionId));
    }

    /**
     * 新增投诉建议
     */
    @Log(title = "投诉建议", businessType = BusinessType.INSERT)
    @PostMapping("save")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content", value = "反馈内容", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "img", value = "凭证", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "phone", value = "联系方式", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "feedback", value = "反馈内容", dataType = "String", dataTypeClass = String.class),
    })
    @RepeatSubmit
    @ApiOperation("新增投诉建议")
    public R<Opinion> add(@ApiIgnore @RequestBody Opinion opinion) {
        opinion.setAccountId(SecurityUtils.getUserId());
        StringUtils.insertRequired(opinion);
        opinion.setType("1");
        opinionService.insertOpinion(opinion);
        return R.ok(opinion);
    }

    /**
     * 修改投诉建议
     */
    @Log(title = "投诉建议", businessType = BusinessType.UPDATE)
    @PostMapping("update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "opinionId", value = "ID", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "accountId", value = "所属用户", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "content", value = "反馈内容", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "img", value = "凭证", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "phone", value = "联系方式", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "feedback", value = "反馈内容", dataType = "String", dataTypeClass = String.class),
    })
    @RepeatSubmit
    @ApiOperation("修改投诉建议")
    public AjaxResult edit(@ApiIgnore @RequestBody Opinion opinion) {
        StringUtils.updateRequired(opinion);
        opinionService.updateOpinion(opinion);
        return success("修改成功");
    }

    /**
     * 删除投诉建议
     */
    @Log(title = "投诉建议", businessType = BusinessType.DELETE)
    @GetMapping("/del")
    @ApiOperation("删除投诉建议")
    public AjaxResult remove(Long opinionId) {
        opinionService.deleteOpinionByOpinionId(opinionId);
        return success("删除成功");
    }
}
